<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$postdata=get_postdata();
$chatmsg = trim($postdata['msg']);
$setting=pdo_get('jy_kefu_set',array('uniacid'=>$_SESSION['uniacid']));
if(empty($setting['isjyrobot']) || empty($setting['jyrobotkey'])){
	$return['error'] = 1;
	$return['msg'] = '没有开启机器人！';
	exi($return);
}
if(empty($chatmsg)){
	$return['error'] = 1;
	$return['msg'] = '请输入对话内容！';
	exi($return);
}
if(empty($postdata['chatid'])){
	$return['error'] = 1;
	$return['msg'] = '会话丢失！';
	exi($return);
}
$resmsg = $this->jinyunrobot($chatmsg);
if(!$resmsg){
	$return['error'] = 1;
	$return['msg'] = '机器人没有返回数据！';
	exi($return);
}else{
	$msg = $resmsg;
}
$getmid = intval($postdata['getmid']);
$setdata =array(
	'nickname' => empty($_SESSION['fans']['nickname']) ? '匿名用户' : $_SESSION['fans']['nickname'],
	'avatar' => empty($_SESSION['fans']['avatar']) ? tomedia($setting['nologo']) : $_SESSION['fans']['avatar'],
	'setmid'=>$_SESSION['uid'],
	'getmid'=>888888888,
	'createtime'=>TIMESTAMP,
	'msg'=>$chatmsg,
	'uniacid' => $_SESSION['uniacid'],
	'chatid' => intval($postdata['chatid']),
	'type' =>1,
);
$robotdata =array(
	'nickname'=>'机器人',
	'setmid'=>888888888,
	'getmid'=>$_SESSION['uid'],
	'createtime'=>TIMESTAMP +1,
	'msg'=>$msg,
	'uniacid' => $_SESSION['uniacid'],
	'chatid' => intval($postdata['chatid']),
	'type' =>1,
);
pdo_insert('jy_kefu_chatlog',$robotdata);
pdo_insert('jy_kefu_chatlog',$setdata);
$return['error'] = 0;
$return['msg'] = $msg;
exi($return);